using System.Windows.Forms;
using WindowsLive.Writer.Api;
using System.Web;

namespace iTunesNowPlaying
{
    [WriterPlugin("81460e42-cd86-454a-a754-8d54a164f271", "Now Playing",
        PublisherUrl = "http://scottisafooldev.spaces.live.com",
        Description = "Automatically puts what you're listening to into the footer of the blog entry.",
        ImagePath = "writer.png",
        HasEditableOptions = true)]

    public class Plugin : HeaderFooterSource
    {
        Settings m_default;

        public override void Initialize(IProperties pluginOptions)
        {
            base.Initialize(pluginOptions);
            m_default = new Settings(pluginOptions);
        }

        public override bool RequiresPermalink
        {
            get
            {
                return false;
            }
        }

        public override string GeneratePreviewHtml(ISmartContent smartContent, IPublishingContext publishingContext, out HeaderFooterSource.Position position)
        {
            position = Position.Footer;
            return NowPlaying();
        }

        private string NowPlaying()
        {
            Track track = new Track();
            track.GetTrackInfo();
            return m_default.GetText(m_default.ShowAlbum, m_default.ShowArtist, m_default.ShowTitle, false, m_default.Prefix,
                track.Album, track.Artist, track.Title);
        }

        public override string GeneratePublishHtml(IWin32Window dialogOwner, ISmartContent smartContent, IPublishingContext publishingContext, bool publish, out HeaderFooterSource.Position position)
        {
            position = Position.Footer;
            return NowPlaying();
        }

        public override void EditOptions(IWin32Window dialogOwner)
        {
            frmOptions op = new frmOptions(m_default);
            op.ShowDialog();
        }

    }

}
